package org.example.huweb.web.sys_book.controller;

import lombok.RequiredArgsConstructor;
import org.example.Result.Result;
import org.example.Result.ResultUtils;
import org.example.dto.book.BookAddBO;
import org.example.dto.book.BookEditBO;
import org.example.entity.Book;
import org.example.huweb.web.sys_book.service.BookService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated

@RestController
@RequestMapping("/api/book")
@RequiredArgsConstructor

public class BookController {

    private final BookService bookService;

    //新增
    @PostMapping("add")
    public void add(@RequestBody BookAddBO bookAddBO) {
        bookService.add(bookAddBO);
    }

    //编辑
    @PostMapping("edit")
    public Result<Object> edit(@RequestBody BookEditBO bookEditBO) {

        bookService.edit(bookEditBO);

        return ResultUtils.success("编辑成功");
    }

    //分页查询

    @GetMapping("page")
    public Result page(@RequestParam int page, @RequestParam int rows) {
        return ResultUtils.success(bookService.getCarouselList(page, rows));
    }

    //删除
    @PostMapping("delete")
    public void delete(@RequestBody List<Long> idList) {
        bookService.delete(idList);
    }
}
